home *** CD-ROM | disk | FTP | other *** search
- The ZIP file contains this document as well as some simple source code
- outlining how to produce an external program for Winpack 5.4.
-
- Example source code is provided for both QuickBasic and C. Winpack itself
- comes with a Visual Basic example. An external program does NOT have to
- be a Windows program. You can write an external program in any language of
- your choice provided your program adheres to the principles outlined here.
-
- Before examining the code provided, I should explain the general idea of
- external Winpack programs and how they work.
-
- If you are using Winpack you will be familiar with some of the external
- programs available. These programs live in your WINPACK/EXTERN
- directory. You probably already have some such as FINGER and WINPLOG.
- External programs are NOT the same as servers in the true sense. There
- are differences in the way servers and external programs are written and
- used and this explanation refers only to external programs.
-
- To launch an external program you generally give it a command such as
- /FINGER or /WINPLOG. You can either do this from the console in Winpack or
- a connected station can send the command. Winpack will look in the /EXTERN
- directory for a program with the name you have given and if such a program
- exists it will be executed.
-
- Winpack passes certain information to the external program by means of the
- command line. There are always at least four arguments passed from Winpack
- to the external program as well as an optional fifth or more argument.
-
- These arguments are:
-
- The status. This is a number starting at 0 for the first call to
- this session. Subsequently the status number becomes whatever the
- external program returned on the previous call. More on this a
- bit later.
-
- pms_call. This is a string containing the Winpack operator's
- callsign. i.e. it will generally be your callsign.
-
- first_name. This will be the first name of the Winpack operator.
- i.e. it will be your first name as entered when you set up Winpack.
-
- connected_station. This is a string containing the callsign and
- SSID of the station currently connected to you. If you launch the
- external program yourself from within Winpack, it will be your
- callsign. If a remote station invokes the external program it will
- be their callsign.
-
- user_text. This will be a string containing any text the user
- entered when calling the program. For example if you invoked the
- external program FLUFF by typing /FLUFF fred then the text 'fred'
- would be passed to the FLUFF external program as the fifth command
- line argument.
-
- All these command line arguments are MANDATORY except the user text. The
- first four arguments are generated automatically by Winpack. The fifth (or
- subsequent) arguments will only exist if the user types something after
- the program name. Your program should always expect this format of command
- line arguments.
-
- Let's have a look at an example. Suppose the information entered when
- you set up Winpack is as follows. Your callsign is VK2AAK, your first name
- is Andy. Another station with the callsign VK2AAA-9 is connected to you.
- Let's say the external program is named FLUFF.EXE and the connected user
- sends the command '/FLUFF help' to you.
- Winpack will look for the program FLUFF in the /EXTERN directory. If it
- finds it it will send the following command line to FLUFF.EXE.
-
- FLUFF.EXE 0 VK2AAK ANDY VK2AAA-9 help
-
- The 0 is the status number. It is zero because this is the first time we
- have called FLUFF this session. The rest of the arguments are as outlined
- above.
-
- OK so far? Fine. Now the FLUFF program goes away and does whatever it was
- written to do. Before we are done though, we need to pass some information
- back to Winpack. All external programs do this by creating a disk file with
- the same name as the external program but with the suffix .REP. In the case
- of the FLUFF.EXE program, a disk file with the name FLUFF.REP would be
- created.
-
- The format of the .REP file is very simple. The first line is the status
- number with which Winpack should call FLUFF the next time in this session.
- If the status number returned is less than zero then Winpack regards this
- as terminating the session and is therefore all done with FLUFF for the
- time being.
-
- The next and subsequent lines are simply plain ASCII text which is returned
- to the user. Each of these text lines should contain just plain ASCII text
- and should be terminated with a carriage return and a line feed.
-
- The source programs provided in this ZIP file are examples of single session
- external programs. i.e. they are called by Winpack, they do their thing and
- when finished executing, return with the status number set to -1.
-
- The status number mechanism allows external programs to act intelligently.
- The external program can examine the status number and branch to other
- routines depending on the value. One important thing to remember if you
- write multiple session external programs is that you MUST store any interim
- data in a disk file at the end of each session before returning to Winpack.
- If you don't, any program variables etc. will be lost.
-
- OK, what do we get our external program to do? Well, that's up to you but
- you should write any external program in such a way that it executes quickly
- and terminates after each call. i.e. don't try writing an external program
- which takes half an hour to calculate PI to 1 million decimal places before
- returning to Winpack ... Winpack won't like it!
-
- Examples of things you can do are looking up callbook information on a CD-ROM
- or controlling external equipment such as turning on a beacon. Your external
- program could send the contents of a file to the user such as the FINGER
- program does. There are plenty of possibilities ... use your imagination!
-
-
-
- THE SOURCE CODE
-
- First a few general notes about the source code provided. The BASIC code was
- written for Quick Basic 4.5 It is a perfect example of spaghetti programming
- with a liberal sprinkling of GOTO's. It is meant as an illustrative example
- of a Winpack external program, NOT an example of good programming techniques.
- The BASIC code complies OK and the resulting .EXE program has been tested
- with Winpack 5.43. There are a few things which should be done if you are
- going to use this code as a starting point for your own external program.
- It would be nice if the program first looked for an existing .REP file and
- deleted it before running. The supplied program just overwrites the .REP
- file it created last time it was called. I could have provided this function
- but it would have used QB45 libraries which you may not have so I left it
- out.
-
- Also, the BASIC code handles the command line arguments in a different way to
- the C code. In C the user text is picked up as one word per argument from the
- command line. i.e if the user entered '/FLUFF fred andy' then 'fred' would
- be the fifth command line argument and 'andy' would be the sixth. The example
- C code only extracts five arguments from the command line so in the example
- above, the text 'andy' would simply be lost. It wouldn't cause any problems
- however.
-
- In BASIC, the user text is picked up as an entire string complete with
- spaces etc. so in the above example, the fifth command line argument would
- be 'fred andy' and there would be no sixth argument.
-
- The BASIC code is short and should be fairly self-explanatory. It assumes
- that it will reside in the WINPACK\EXTERN directory and that is where it
- puts the .REP response file because that is where Winpack will look for it.
-
- The C code was compiled OK using both Microsoft Quick C and MIX software's
- Power C compilers. It is very straightforward code and should compile OK
- with any common or garden variety compiler. The C language extracts command
- line arguments in the argv[] array and the first entry in this array is
- always the program name. That is why the status is in argv[1], the callsign
- of the Winpack operator is in argv[2] etc. The program name will be in
- argv[0] and could be extracted and used to automatically generate the .REP
- file name. Be aware however that argv[0] will contain the entire path as
- well as the program name, e.g. it might contain C:\WINPACK\EXTERN\FLUFF.EXE.
-
- The same comments apply as for the BASIC source. It is not meant as an
- example of good programming, just to illustrate how a Winpack external
- program works. Again, you could detect and delete an existing .REP file
- but as I don't know what compiler you might be using and what library
- functions it may have, I have kept it simple.
-
- I hope you find the above information of some use. I don't expect or want
- any acknowledgement for the supplied code. Use it, modify it, do whatever
- you want with it. If you come up with any interesting external programs or
- ideas then by all means drop me a packet message to:
- VK2AAK@VK2DYX.NSW.AUS.OC
- or send me an internet email to:
- andykeir@midcoast.com.au
-
- 73'
-
- Andy. VK2AAK
-
-